
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        学生管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <script type="text/javascript" src="lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>学生管理</cite></a>
              <a><cite>学生信息</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:80%">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">

                <div class="layui-input-inline">
                    <input type="text" id="st_ID"  placeholder="请输入学生ID" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button type="button" class="layui-btn" id="btnfindByST_ID" ><i class="layui-icon">&#xe615;</i></button>
                </div>
                <div class="layui-input-inline">
                    <label></label>
                </div>
                <div class="layui-input-inline">
                    <input type="text" id="st_NAME" placeholder="请输入学生用户名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn" type="button" id="btnfindByST_NAME" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>
    <xblock>
        <button class="layui-btn" onclick="building_add('添加学生信息','buildingadd.html','1000','600')">
            <i class="layui-icon">&#xe608;</i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge" ><label id="st_n">2</label></span> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>

            <th>
                #
            </th>
            <th>
                学生编号
            </th>
            <th>
                用户名
            </th>
            <th>
                密码
            </th>
            <th>
                年龄
            </th>
            <th>
                部门
            </th>
            <th>
                性别
            </th>
            <th>
                真实姓名
            </th>
            <th>
                操作
            </th>
        </tr>
        </thead>
        <tbody id="st_info">
        <tr>
            <td>
                2                        </td>
            <td>
                金华万府                        </td>
            <td >
                CJ20191210001                        </td>
            <td >
                A栋                        </td>
            <td >
                200                        </td>
            <td >
                金华万府A栋                        </td>
            <td >
                2019-12-10 21:55:17                        </td>
            <td class="td-manage">
                <a title="编辑" href="javascript:;" onclick="building_edit('编辑','buildingadd.html','2','1000','600')"
                   class="ml-5" style="text-decoration:none">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" href="javascript:;" onclick="building_del(this,'2')"
                   style="text-decoration:none">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        </tbody>
    </table>

    <div id="page"><ul class="pagination"><li class="disabled"><span>&laquo;</span></li> <li class="active"><span>1</span></li><li><a href="">&raquo;</a></li></ul></div>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>
<script>
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        okLoading.close($);
        $(function (){
            studentInfo()
            $("#btnfindByST_ID").click(function (){
                var id = $("#st_ID").val()
                // alert(id)
                $.ajax({
                    url: "/student/findByID?st_ID="+id,
                    async:true,
                    dataType: "json",
                    contentType:"application/json",
                    success:function (res){
                        if(res.state === 200) {
                            var e = res.data
                            var sex = '男'
                            if (e.gender !== 1){ sex = '女'}
                            $("#st_info").empty()
                            $("#st_info").append("<tr>")
                                .append("<td>" + 1 +"</td>")
                                .append("<td>" + e.st_ID + "</td>")
                                .append("<td>" + e.userName + "</td>")
                                .append("<td>" + e.password + "</td>")
                                .append("<td>" + e.age + "</td>")
                                .append("<td>" + e.department + "</td>")
                                .append("<td>" + sex + "</td>")
                                .append("<td>" + e.realName + "</td>")
                                .append("<td>" +
                                    "<button type='button' class='btn btn-primary col-md-3' onclick='community_edit("+e.st_ID+")'>修改</button>"+
                                    "<button type='button' class='btn btn-success col-md-3' onclick='dc_del("+e.st_ID+")' value='删除'>删除</button>" +
                                    "</td></tr>")

                        }
                        $("#dc_n").text(1);
                    }
                })
            })
            $("#btnfindByST_NAME").click(function (){
                var name = $("#st_NAME").val()
                // alert(name)
                $.ajax({
                    url:"/student/findByName?userName="+name,
                    dataType:"json",
                    contentType: "application/json",
                    success: function (res){
                        if(res.state === 200){
                            var e = res.data
                            var sex = '男'
                            if (e.gender !== 1){ sex = '女'}
                            $("#st_info").empty()
                            $("#st_info").append("<tr>")
                                .append("<td>"+ 1 +"</td>")
                                .append("<td>" + e.st_ID + "</td>")
                                .append("<td>" + e.userName + "</td>")
                                .append("<td>" + e.password + "</td>")
                                .append("<td>" + e.age + "</td>")
                                .append("<td>" + e.department + "</td>")
                                .append("<td>" + sex + "</td>")
                                .append("<td>" + e.realName + "</td>")
                                .append("<td>" +
                                    "<button type='button' class='btn btn-primary col-md-3' onclick='building_edit("+e.st_ID+")'>修改</button>"+
                                    "<button type='button' class='btn btn-success col-md-3' onclick='st_del("+e.st_ID+")' value='删除'>删除</button>" +
                                    "</td></tr>")
                            $("#st_n").text(1);
                        }
                    }
                })
            })
        })

    });


    /*添加*/
    function building_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }
    //编辑
    function building_edit (id) {
        url = "buildingmod.html?st_ID="+id;
        x_admin_show('修改',url,1000,600);
    }
    /*删除*/
    function st_del(st_id){
        $.ajax({
            url:"/student/delete?st_ID="+st_id,
            dataType:"json",
            success: function (res){
                if(res.state === 200){
                    alert("删除成功")
                    location.reload()
                }
            }
        })
    }



    function studentInfo() {
        $.ajax({
            url: "/student/findAll",
            dataType: "json",
            async:true,
            success(res) {
                if (res.state === 200) {
                    var n = 0;
                    $("#st_info").empty()
                    $.each(res.data, function (i, e) {
                        n++;
                        var sex = '男'
                        if(e.gender !== 1){sex = '女'}
                        $("#st_info").append("<tr>")
                            .append("<td>" + (i+1) +"</td>")
                            .append("<td>" + e.st_ID + "</td>")
                            .append("<td>" + e.userName + "</td>")
                            .append("<td>" + e.password + "</td>")
                            .append("<td>" + e.age + "</td>")
                            .append("<td>" + e.department + "</td>")
                            .append("<td>" + sex + "</td>")
                            .append("<td>" + e.realName + "</td>")
                            .append("<td>" +
                                "<button type='button' class='btn btn-primary col-md-3' onclick='building_edit("+e.st_ID+")'>修改</button>"+
                                "<button type='button' class='btn btn-success col-md-3' onclick='st_del("+e.st_ID+")' value='删除'>删除</button>" +
                                "</td></tr>")

                    })
                    $("#st_n").text(n);
                }
            }
        })
    }
</script>

</body>
</html>